home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Mesa-2.2 / src-glu / nurbs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-27  |  5.2 KB  |  225 lines

  1. /* $Id: nurbs.h,v 1.1 1996/09/27 01:19:39 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.0
  6.  * Copyright (C) 1995-1996  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * $Log: nurbs.h,v $
  26.  * Revision 1.1  1996/09/27 01:19:39  brianp
  27.  * Initial revision
  28.  *
  29.  */
  30.  
  31.  
  32. /*
  33.  * NURBS implementation written by Bogdan Sikorski (bogdan@cira.it)
  34.  * See README2 for more info.
  35.  */
  36.  
  37.  
  38. #include <stdlib.h>
  39. #include "gluP.h"
  40.  
  41. #define EPSILON 1e-06 /* epsilon for double precision compares */
  42.  
  43. typedef enum
  44. {
  45.     GLU_NURBS_CURVE, GLU_NURBS_SURFACE, GLU_NURBS_TRIM, GLU_NURBS_NO_TRIM,
  46.     GLU_NURBS_TRIM_DONE, GLU_NURBS_NONE
  47. } GLU_nurbs_enum;
  48.  
  49. typedef enum
  50. {
  51.     GLU_TRIM_NURBS, GLU_TRIM_PWL
  52. } GLU_trim_enum;
  53.  
  54. typedef struct
  55. {
  56.     GLint    sknot_count;
  57.     GLfloat    *sknot;
  58.     GLint    tknot_count;
  59.     GLfloat    *tknot;
  60.     GLint    s_stride;
  61.     GLint    t_stride;
  62.     GLfloat    *ctrlarray;
  63.     GLint    sorder;
  64.     GLint    torder;
  65.     GLint    dim;
  66.     GLenum    type;
  67. } surface_attribs;
  68.  
  69. typedef struct
  70. {
  71.     surface_attribs    geom;
  72.     surface_attribs    color;
  73.     surface_attribs    texture;
  74.     surface_attribs    normal;
  75. } nurbs_surface;
  76.  
  77. typedef struct
  78. {
  79.     GLint            knot_count;
  80.     GLfloat            *knot;
  81.     GLint            stride;
  82.     GLfloat            *ctrlarray;
  83.     GLint            order;
  84.     GLint            dim;
  85.     GLenum            type;
  86. } curve_attribs;
  87.  
  88. typedef struct
  89. {
  90.     GLint            pt_count;
  91.     GLfloat            *ctrlarray;
  92.     GLint            stride;
  93.     GLint            dim;
  94.     GLenum            type;
  95. } pwl_curve_attribs;
  96.  
  97. typedef struct
  98. {
  99.     curve_attribs    geom;
  100.     curve_attribs    color;
  101.     curve_attribs    texture;
  102.     curve_attribs    normal;
  103. } nurbs_curve;
  104.  
  105. typedef struct trim_list_str
  106. {
  107.     GLU_trim_enum            trim_type;
  108.     union
  109.     {
  110.         pwl_curve_attribs    pwl_curve;
  111.         curve_attribs        nurbs_curve;
  112.     }                        curve;
  113.     struct trim_list_str    *next;
  114. } trim_list;
  115.  
  116. typedef struct seg_trim_str
  117. {
  118.     GLfloat             *points;
  119.     GLint                pt_cnt,seg_array_len;
  120.     struct seg_trim_str    *next;
  121. } trim_segments;
  122.  
  123. typedef struct nurbs_trim_str
  124. {
  125.     trim_list                *trim_loop;
  126.     trim_segments            *segments;
  127.     struct nurbs_trim_str    *next;
  128. } nurbs_trim;
  129.  
  130. typedef struct
  131. {
  132.     GLfloat model[16],proj[16],viewport[4];
  133. } culling_and_sampling_str;
  134.  
  135. struct GLUnurbsObj {
  136.     GLboolean        culling;
  137.     GLenum            error;
  138.     void            (*error_callback)( GLenum err );
  139.     GLenum            display_mode;
  140.     GLU_nurbs_enum    nurbs_type;
  141.     GLboolean        auto_load_matrix;
  142.     culling_and_sampling_str
  143.                     sampling_matrices;
  144.     GLfloat            sampling_tolerance;
  145.     nurbs_surface    surface;
  146.     nurbs_curve        curve;
  147.     nurbs_trim        *trim;
  148. };
  149.  
  150. typedef struct
  151. {
  152.     GLfloat        *knot;
  153.     GLint        nknots;
  154.     GLfloat        *unified_knot;
  155.     GLint        unified_nknots;
  156.     GLint        order;
  157.     GLint        t_min,t_max;
  158.     GLint        delta_nknots;
  159.     GLboolean    open_at_begin,open_at_end;
  160.     GLfloat        *new_knot;
  161.     GLfloat        *alpha;
  162. } knot_str_type;
  163.  
  164. typedef struct
  165. {
  166.     GLfloat    *geom_ctrl;
  167.     GLint    geom_s_stride,geom_t_stride;
  168.     GLfloat    **geom_offsets;
  169.     GLint    geom_s_pt_cnt,geom_t_pt_cnt;
  170.     GLfloat    *color_ctrl;
  171.     GLint    color_s_stride,color_t_stride;
  172.     GLfloat    **color_offsets;
  173.     GLint    color_s_pt_cnt,color_t_pt_cnt;
  174.     GLfloat *normal_ctrl;
  175.     GLint    normal_s_stride,normal_t_stride;
  176.     GLfloat    **normal_offsets;
  177.     GLint    normal_s_pt_cnt,normal_t_pt_cnt;
  178.     GLfloat    *texture_ctrl;
  179.     GLint    texture_s_stride,texture_t_stride;
  180.     GLfloat    **texture_offsets;
  181.     GLint    texture_s_pt_cnt,texture_t_pt_cnt;
  182.     GLint    s_bezier_cnt,t_bezier_cnt;
  183. } new_ctrl_type;
  184.  
  185. void call_user_error( GLUnurbsObj *nobj, GLenum error );
  186.  
  187. GLenum test_knot(GLint nknots, GLfloat *knot, GLint order);
  188.  
  189. GLenum explode_knot(knot_str_type *the_knot);
  190.  
  191. GLenum calc_alphas(knot_str_type *the_knot);
  192.  
  193. GLenum calc_new_ctrl_pts(GLfloat *ctrl,GLint stride,knot_str_type *the_knot,
  194.     GLint dim,GLfloat **new_ctrl,GLint *ncontrol);
  195.  
  196. GLenum glu_do_sampling_2D(GLUnurbsObj *nobj, GLfloat *new_ctrl,GLint n_ctrl,
  197.     GLint order,GLint dim,GLint **factors);
  198.  
  199. GLenum glu_do_sampling_3D(GLUnurbsObj *nobj, new_ctrl_type *new_ctrl,
  200.     int **sfactors, GLint **tfactors);
  201.  
  202. GLboolean fine_culling_test_2D(GLUnurbsObj *nobj, GLfloat *ctrl, GLint n_ctrl,
  203.     GLint stride, GLint dim);
  204.  
  205. GLboolean fine_culling_test_3D(GLUnurbsObj *nobj, GLfloat *ctrl,
  206.     GLint s_n_ctrl, GLint t_n_ctrl, GLint s_stride, GLint t_stride, GLint dim);
  207.  
  208. void do_nurbs_curve( GLUnurbsObj *nobj);
  209.  
  210. void do_nurbs_surface( GLUnurbsObj *nobj);
  211.  
  212. GLenum patch_trimming(GLUnurbsObj *nobj,new_ctrl_type *new_ctrl,
  213.     GLint *sfactors, GLint *tfactors);
  214.  
  215. void collect_unified_knot(knot_str_type *dest, knot_str_type *src,
  216.     GLfloat maximal_min_knot, GLfloat minimal_max_knot);
  217.  
  218. GLenum select_knot_working_range(GLUnurbsObj *nobj,knot_str_type *geom_knot,
  219.     knot_str_type *color_knot, knot_str_type *normal_knot,
  220.     knot_str_type *texture_knot);
  221.  
  222. void free_unified_knots(knot_str_type *geom_knot, knot_str_type *color_knot,
  223.     knot_str_type *normal_knot, knot_str_type *texture_knot);
  224.  
  225.